<?php

declare(strict_types=1);

namespace app\model\admin;

use app\model\AdminBaseModel;
use app\model\member\MpConfig;

/**
 * @mixin \think\Model
 */
class SysMember extends AdminBaseModel
{
    //
    // 数据表名称
    protected $table = 'member_user';
    protected $scopeField = false;

    //可搜索字段
    protected $searchField = [];
    protected $singleSearchField = ['username', 'nickname'];
    //可作为条件的字段
    protected $whereField = ['parent_id', 'status', 'phone'];
    //可做为时间范围查询的字段
    protected $timeField = ['create_time'];
    //不允许删除的ID
    public $noDeletionId = [];

    // public function setPasswordAttr($value)
    // {
    //     storage_log('value' . $value);
    //     storage_log("mdg5" . md5($value));
    //     return md5($value);
    // }

    public function group()
    {
        return $this->belongsTo(SysMemberGroup::class, 'group_id')->bind(['group_name']);
    }
    public function getChannelCodeAttr($value)
    {
        if ($value) {
            return unserialize($value);
        }
    }
    public function setChannelCodeAttr($value)
    {
        if ($value) {
            return serialize($value);
        }
    }
    // public function getPasswordAttr($value)
    // {
    //     if ($value) {
    //         return "";
    //     }
    // }
    // public function setPasswordAttr($value)
    // {
    //     if ($value) {
    //         return md5($value);
    //     } else {
    //         return md5("123456");
    //     }
    // }
    public function mpconfig()
    {
        // return $this->hasOne(MpConfig::class, 'sys_user_id', 'id');
    }
}
